<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let str = "2012-12-20";

      // 截取字符串 ① 正则表达式匹配字符串 ② 给想要截取的部分加上括号
      console.log(str.match(/((\d{4})-(\d{2}))-(\d{2})/));
      console.log(str.match(/(\d{4})-(\d{2})-(\d{2})/));
      console.log(str.match(/(\d{4})-((\d{2})-(\d{2}))/));
    </script>
  </body>
</html>
